﻿using DG.Tweening;
using Helpers;
using UnityEngine;

namespace Gp.Scripts.Core {
    public class HitGestureTrigger : UnitGestureTrigger {
        private Tween tweener = null;
        private Tween _hitTweener = null;
        private Vector3 _force;

        
        public HitGestureTrigger(Vector3 force) {
            _force = force;
        }


        public override void OnTrigger() {
            var selfPos = UnitReference.transform.position;
            // 得到局部坐标系下目标点位置
            // var targetPoint = UnitReference.transform.worldToLocalMatrix.MultiplyPoint(selfPos + _force);
            // var selfForce = targetPoint - UnitReference.transform.localPosition;


            // float impactForce = selfForce.magnitude / 15;
            // Vector3 impactDirection = selfForce.normalized;
            // Animator.SetFloat(UnitAnimatorParameter.ImpactForceFloat, impactForce);
            // Animator.SetFloat(UnitAnimatorParameter.ImpactForceXFloat, impactDirection.x);
            // Animator.SetFloat(UnitAnimatorParameter.ImpactForceYFloat, impactDirection.y);
            // Animator.Play(UnitAnimatorStateId.OnDamage);
            
            
            // 单位闪烁
            tweener?.Kill();
            _hitTweener?.Kill();
            tweener     = EntityVxHelper.TriggerHitHighlightEffect(Model);
            _hitTweener = UnitReference.transform.DOShakePosition(.2f, Vector3.up);
        }
    }
}